import 'package:flutter/material.dart';
import 'package:fzcgx_app/common/adapter_utils.dart';
import 'package:fzcgx_app/common/assets_utils.dart';
import 'package:fzcgx_app/provider/provider_widget.dart';
import 'package:fzcgx_app/ui/order/view_model/order_rob_view_model.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class OrderRobPage extends StatefulWidget {
  OrderRobPage({Key key}) : super(key: key);

  @override
  _OrderRobPageState createState() => _OrderRobPageState();
}

class _OrderRobPageState extends State<OrderRobPage>
    with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController _tabController;
  List _titleList = ['全部', '已完成', '待验收', '待付款', '已失效'];
  @protected
  bool get wantKeepAlive => true;
  @override
  void initState() {
    super.initState();
    _tabController = null;
    _tabController = TabController(
        initialIndex: 0, length: _titleList.length, vsync: this); // 直接传this

    print("---->${_tabController.previousIndex}");

    if (_tabController.indexIsChanging) {
      print("---->indexch");
    }
  }

  @override
  // ignore: must_call_super
  Widget build(BuildContext context) {
    return ProviderWidget<OrderRobViewModel>(
      model: OrderRobViewModel(),
      builder: (context, viewModel, child) {
        return Scaffold(
          backgroundColor: Color(0xffF5F5F5),
          body: SafeArea(
              child: Column(
            children: <Widget>[
              SizedBox(height: AdapterUtils.getHeight(10)),
              Container(
                child: TabBar(
                  controller: _tabController,
                  isScrollable: false,
                  indicatorColor: Color(0xff15A1FF),
                  indicatorWeight: 2,
                  indicatorSize: TabBarIndicatorSize.label,
                  labelStyle: TextStyle(
                      color: Color(0xff15A1FF),
                      fontWeight: FontWeight.w500,
                      fontSize: AdapterUtils.getSp(14)),
                  labelColor: Color(0xff15A1FF),
                  unselectedLabelColor: Color(0xff3B4859),
                  unselectedLabelStyle: TextStyle(
                      color: Color(0xff3B4859),
                      fontWeight: FontWeight.w500,
                      fontSize: AdapterUtils.getSp(14)),
                  tabs: _titleList.map((f) {
                    return Tab(
                      text: f,
                    );
                  }).toList(),
                ),
              ),
              Expanded(
                  child: SmartRefresher(
                controller: viewModel.refreshController,
                enablePullDown: true,
                enablePullUp: true,
                onRefresh: viewModel.onRefresh,
                onLoading: viewModel.onLoading,
                
                header: WaterDropHeader(
                  waterDropColor: Color(0xff15A1FF),
                ),
                child: ListView.builder(
                  itemCount: 2,
                  itemBuilder: (BuildContext context, int index) {
                    return Container(
                      margin: EdgeInsets.only(
                          bottom: AdapterUtils.getHeight(10),
                          top: index == 0 ? AdapterUtils.getHeight(10) : 0),
                      child: _buildOrderItemWidget(),
                    );
                  },
                ),
              )),
            ],
          )),
        );
      },
    );
  }

  Widget _buildOrderItemWidget() {
    return Container(
      width: AdapterUtils.screenWidth(),
      margin: EdgeInsets.only(
        left: AdapterUtils.getWidth(15),
        right: AdapterUtils.getWidth(15),
      ),
      padding: EdgeInsets.all(AdapterUtils.getWidth(12)),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(12))),
      child: Column(
        children: <Widget>[
          Container(
            child: Row(
              children: <Widget>[
                Text('超越兄弟服饰',
                    style: TextStyle(
                        color: Color(0xff3B4859),
                        fontWeight: FontWeight.w600,
                        fontSize: AdapterUtils.getSp(16))),
                SizedBox(
                  width: AdapterUtils.getWidth(10),
                ),
                Image.asset(
                  AssetsUtils.getAssetsImagesPath('home_arrow_right.png'),
                ),
                SizedBox(
                  width: AdapterUtils.getWidth(10),
                ),
                Container(
                  constraints: BoxConstraints.expand(
                    height: AdapterUtils.getHeight(16),
                    width: AdapterUtils.getWidth(36),
                  ),
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(AssetsUtils.getAssetsImagesPath(
                        'tag_red.png',
                      )),
                      //这里是从assets静态文件中获取的，也可以new NetworkImage(）从网络上获取
                      centerSlice: Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
                    ),
                  ),
                  alignment: Alignment.center,
                  child: Text('抢单',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          color: Colors.white,
                          fontWeight: FontWeight.w500,
                          fontSize: AdapterUtils.getSp(8))),
                ),
                Spacer(),
                Text('待验收',
                    style: TextStyle(
                        color: Color(0xff15A1FF),
                        fontWeight: FontWeight.w500,
                        fontSize: AdapterUtils.getSp(13))),
              ],
            ),
          ),
          Container(
            child: Row(
              children: <Widget>[
                Image.network(
                  'http://test.fuzhuangchangongxiao.cn/public/Uploads/2020/proImg.png',
                  width: AdapterUtils.getWidth(90),
                  height: AdapterUtils.getHeight(90),
                  fit: BoxFit.cover,
                ),
                Expanded(
                    child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('2020款式春夏风衣系列成衣外发加工',
                        style: TextStyle(
                            color: Color(0xff303030),
                            fontWeight: FontWeight.w600,
                            fontSize: AdapterUtils.getSp(14))),
                    SizedBox(height: AdapterUtils.getHeight(4)),
                    Row(
                      children: <Widget>[
                        Text('风衣',
                            style: TextStyle(
                                color: Color(0xffA0A0A0),
                                fontWeight: FontWeight.w500,
                                fontSize: AdapterUtils.getSp(12))),
                        Spacer(),
                        Text('x5000',
                            style: TextStyle(
                                color: Color(0xffA0A0A0),
                                fontWeight: FontWeight.w500,
                                fontSize: AdapterUtils.getSp(12))),
                      ],
                    ),
                    SizedBox(height: AdapterUtils.getHeight(8)),
                    RichText(
                      text: TextSpan(children: <InlineSpan>[
                        TextSpan(
                          text: '发布方电话：',
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(12),
                            color: Color(0xff606B79),
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        TextSpan(
                          text: '13580920364',
                          style: TextStyle(
                            fontSize: AdapterUtils.getSp(12),
                            color: Color(0xffFF3D3E),
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ]),
                    ),
                  ],
                ))
              ],
            ),
          ),
          SizedBox(
            height: AdapterUtils.getHeight(17),
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                RichText(
                  text: TextSpan(children: <InlineSpan>[
                    TextSpan(
                      text: '单价',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '￥',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(10),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '50.00',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ]),
                ),
                SizedBox(
                  width: AdapterUtils.getWidth(10),
                ),
                RichText(
                  text: TextSpan(children: <InlineSpan>[
                    TextSpan(
                      text: '保证金',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '￥',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(10),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '10.00',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff99A2AD),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ]),
                ),
                SizedBox(
                  width: AdapterUtils.getWidth(10),
                ),
                RichText(
                  text: TextSpan(children: <InlineSpan>[
                    TextSpan(
                      text: '实付款',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff141F33),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '￥',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(10),
                        color: Color(0xff141F33),
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    TextSpan(
                      text: '50010.00',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(14),
                        color: Color(0xff141F33),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ]),
                ),
              ],
            ),
          ),
          SizedBox(
            height: AdapterUtils.getHeight(17),
          ),
          Container(
            child: Row(
              children: <Widget>[
                Expanded(
                    child: InkWell(
                  child: Container(
                    height: AdapterUtils.getHeight(30),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        border: Border.all(color: Color(0xffD7D8DB), width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(15))),
                    child: Text('确认验收',
                        style: TextStyle(
                            color: Color(0xff15A1FF),
                            fontWeight: FontWeight.w500,
                            fontSize: AdapterUtils.getSp(12))),
                  ),
                ))
              ],
            ),
          )
        ],
      ),
    );
  }
}
